package com.zzyl.nursing.controller.member;

import com.zzyl.common.core.controller.BaseController;
import com.zzyl.common.core.domain.R;
import com.zzyl.common.core.page.TableDataInfo;
import com.zzyl.common.exception.base.BaseException;
import com.zzyl.common.utils.PageUtils;
import com.zzyl.nursing.controller.NursingProjectController;
import com.zzyl.nursing.domain.NursingProject;
import com.zzyl.nursing.dto.OrdersProjectPageParamDTO;
import com.zzyl.nursing.service.INursingProjectService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/member/orders/project")
@Api(tags = "小程序项目订单管理")
@Slf4j
public class OrdersProjectController extends BaseController {

    @Autowired
    private INursingProjectService  nursingProjectService;


    @ApiOperation("查询项目列表")
    @GetMapping("/page")

    public TableDataInfo<List<NursingProject>> list(@ApiParam("护理项目查询条件")  NursingProject nursingProject) {
        int pageNum = PageUtils.getPageNum();
        int pageSize = PageUtils.getPageSize();

        // 获取总记录数
        int total = (int)nursingProjectService.count();

        // 计算总页数
        int totalPages = (int) Math.ceil((double) total / pageSize);

        // 如果请求页码大于总页数，则跳转到最后一页
        if (totalPages > 0 && pageNum > totalPages) {
            throw new BaseException("下面没有内容了~");
        }

        // 启动分页
        PageUtils.startPage(pageNum, pageSize);
        List<NursingProject> list = nursingProjectService.selectNursingProjectList(nursingProject);
        return getDataTable(list);
    }

    @GetMapping(value = "/{id}")
    @ApiOperation("获取项目详细信息")
    public R<NursingProject> getInfo(@ApiParam("护理项目ID") @PathVariable("id") Long id)
    {
        return R.ok(nursingProjectService.selectNursingProjectById(id));
    }

}
